package com.dw.etl.core.service;

import com.dw.etl.common.util.UUIDUtil;
import  com.dw.etl.common.vo.PaginationVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.dw.etl.core.api.BaseIndexConfFdService;
import com.dw.etl.core.mapper.BaseIndexConfFdMapper;
import com.dw.etl.core.bean.model.BaseIndexConfFd;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * baseIndexConfFd服务实现类
 * Created by hozeData on 2021/06/23.
 */
@Service
@Transactional
public class BaseIndexConfFdServiceImpl implements BaseIndexConfFdService{

    private static final Logger LOGGER = LoggerFactory.getLogger(BaseIndexConfFdServiceImpl.class);

    @Autowired
    private BaseIndexConfFdMapper baseIndexConfFdMapper;

    @Override
    public int insert(BaseIndexConfFd baseIndexConfFd) {
        if(StringUtils.isEmpty(baseIndexConfFd.getPk())){
            String uuid32 = UUIDUtil.getUUID32();
            baseIndexConfFd.setPk(uuid32);
        }
        return baseIndexConfFdMapper.insert(baseIndexConfFd);
    }

    @Override
    public int insertSelective(BaseIndexConfFd baseIndexConfFd)  {
        if(StringUtils.isEmpty(baseIndexConfFd.getPk())){
            String uuid32 = UUIDUtil.getUUID32();
            baseIndexConfFd.setPk(uuid32);
        }
        return baseIndexConfFdMapper.insertSelective(baseIndexConfFd);
    }

    @Override
    public int deleteById(String pk)  {
        return baseIndexConfFdMapper.deleteByPrimaryKey(pk);
    }

    @Override
    public int updateByIdSelective(BaseIndexConfFd baseIndexConfFd)  {

        return baseIndexConfFdMapper.updateByPrimaryKeySelective(baseIndexConfFd);
    }

    @Override
    public int updateById(BaseIndexConfFd baseIndexConfFd)  {
        return baseIndexConfFdMapper.updateByPrimaryKey(baseIndexConfFd);
    }

    @Override
    public BaseIndexConfFd getById(String pk)  {
        return baseIndexConfFdMapper.selectByPrimaryKey(pk);
    }

    @Override
    public List<BaseIndexConfFd> findByModel(BaseIndexConfFd baseIndexConfFd)  {
        return baseIndexConfFdMapper.findByModel(baseIndexConfFd);
    }

    @Override
    public PaginationVO<BaseIndexConfFd> findPageByModel(BaseIndexConfFd baseIndexConfFd, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum == null? 1 : pageNum, pageSize == null? 10 : pageSize);
        List<BaseIndexConfFd> quesList = baseIndexConfFdMapper.findByModel(baseIndexConfFd);
        PageInfo<BaseIndexConfFd> pageInfo = new PageInfo<>(quesList);
        PaginationVO<BaseIndexConfFd> paginationVo = new PaginationVO(pageInfo.getTotal(), pageInfo.getList());
        return paginationVo;
    }





}
